angular.module('starter.services', [])

.factory('Chats', function() {
  // Might use a resource here that returns a JSON array

  // Some fake testing data
  var chats = [{
    id: 0,
    name: 'Ben Sparrow',
    lastText: 'You on your way?',
    face: 'img/ben.png'
  }, {
    id: 1,
    name: 'Max Lynx',
    lastText: 'Hey, it\'s me',
    face: 'img/max.png'
  }, {
    id: 2,
    name: 'Adam Bradleyson',
    lastText: 'I should buy a boat',
    face: 'img/adam.jpg'
  }, {
    id: 3,
    name: 'Perry Governor',
    lastText: 'Look at my mukluks!',
    face: 'img/perry.png'
  }, {
    id: 4,
    name: 'Mike Harrington',
    lastText: 'This is wicked good ice cream.',
    face: 'img/mike.png'
  }];

  return {
    all: function() {
      return chats;
    },
    remove: function(chat) {
      chats.splice(chats.indexOf(chat), 1);
    },
    get: function(chatId) {
      for (var i = 0; i < chats.length; i++) {
        if (chats[i].id === parseInt(chatId)) {
          return chats[i];
        }
      }
      return null;
    }
  };
})
.factory('HomeService', function ($http,$q,$timeout) {
  var homeBanner = [
    {
      url:"img/banner1.png"
    },{
      url:"img/banner2.jpg"
    },{
      url:"img/banner3.jpg"
    },{
      url:"img/banner4.jpg"
    }
  ]
  function getHomeBanner (){
    var deferred = $q.defer();
    var data = [];
    var url = ""
    $timeout(function () {
      deferred.resolve(homeBanner)
    },1000)
    //$http.jsonp(url).success(function (data) {
    //  deferred.resolve(data);
    //}).error(function (error) {
    //  console.log(error);
    //});
    return deferred.promise;
  }
  var goodsBanner = [
    {
      url:"img/goods/shop_banner.jpg"
    },{
      url:"img/goods/shop_banner.jpg"
    },
    {
      url:"img/goods/shop_banner.jpg"
    },
    {
      url:"img/goods/shop_banner.jpg"
    },
    {
      url:"img/goods/shop_banner.jpg"
    },
    {
      url:"img/goods/shop_banner.jpg"
    }
  ]
  function getGoodsBanner (){
    var deferred = $q.defer();
    var data = [];
    var url = ""
    $timeout(function () {
      deferred.resolve(goodsBanner)
    },1000)
    //$http.jsonp(url).success(function (data) {
    //  deferred.resolve(data);
    //}).error(function (error) {
    //  console.log(error);
    //});
    return deferred.promise;
  }
  return {
    getHomeBanner:getHomeBanner,
    getGoodsBanner:getGoodsBanner
  }

})
